//
//  MainNavigationController.swift
//  声网demo
//
//  Created by 秦江涛 on 2022/9/8.
//

import UIKit

class MainNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    

    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        if children.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
            
            let backBtn = UIButton().then {
                $0.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
                $0.setImage(UIImage(named: "back"), for: .normal)
                $0.addTarget(self, action: #selector(backBtnClick), for: .touchUpInside)
            }
            let backNavigationItem = UIBarButtonItem(customView: backBtn)
            viewController.navigationItem.leftBarButtonItem = backNavigationItem
        }
        super.pushViewController(viewController, animated: animated)
    }
    
//    override func popViewController(animated: Bool) -> UIViewController? {
//        super.popViewController(animated: animated)
//    }
    
    @objc private func backBtnClick() {
        self.popViewController(animated: true)
    }
}
